//
//  MyCollectionViewCell.m
//  UIhomework_14
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "MyCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "MovieModel.h"

@interface MyCollectionViewCell ()

@property (nonatomic, retain) UIImageView *imgview;
@property (nonatomic, retain) UILabel *label;

@end

@implementation MyCollectionViewCell


-(void)dealloc{
    [_imgview release];
    [_label release];
    [super dealloc];
}

- (instancetype) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

-(void)setModel:(MovieModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        [self fuzhi];
    }
}

- (void)fuzhi{
    [_imgview sd_setImageWithURL:[NSURL URLWithString:_model.image]];
    _label.text = _model.title;
}

- (void)createSubviews{
    self.imgview = [[UIImageView alloc] init];
    [self.contentView addSubview:_imgview];
    [_imgview release];
    
    self.label = [[UILabel alloc] init];
    [self.contentView addSubview:_label];
    [_label release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    _imgview.frame = CGRectMake(0, 0, layoutAttributes.frame.size.width, layoutAttributes.frame.size.height - 30);
    _imgview.backgroundColor = [UIColor redColor];
    
    
    _label.frame = CGRectMake(0, layoutAttributes.frame.size.height-30, layoutAttributes.frame.size.width, 30);
//    _label.
    _label.textAlignment = NSTextAlignmentCenter;
   // _label.backgroundColor = [UIColor greenColor];
}




@end
